package chenbi.renthouse.service.impl;

import chenbi.renthouse.controller.request.HousePageRequest;
import chenbi.renthouse.entity.House;
import chenbi.renthouse.mapper.HouseMapper;
import chenbi.renthouse.service.IHouseService;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class HouseService implements IHouseService {
    @Autowired(required = false)
    HouseMapper houseMapper;

    @Override
    public List<House> list() {
        return houseMapper.list();
    }

    @Override
    public Object page(HousePageRequest housePageRequest) {

        PageHelper.startPage(housePageRequest.getPageNum(),housePageRequest.getPageSize());
        List<House> houses = houseMapper.listByCondition(housePageRequest);
        return new PageInfo<>(houses);
    }

    @Override
    public void save(House house) {
        Date date = new Date();
        // 当做卡号来处理
        house.setHouseaccount(DateUtil.format(date,"yyyyMMdd")+Math.abs(IdUtil.fastSimpleUUID().hashCode()));
        houseMapper.save(house);

    }


}
